var ligerGrid;

$(function() {
			var options = {
				queryKey : queryKey,
				pageSize : 30,
				gridWidth : null,
				gridHeight : 580,
				showIdx : false,
				// init param for groove.query, property querykey is reserved,
				// property method is reserved,
				params : {
					pkid : pkid
				},
				// init param for groove.view, property id is reserved
				viewParams : {
					pkid : pkid
				},
				gridRender : function(grid) {
					ligerGrid = grid;
				}
			};
			var gridPanel = new $.grooveQuery(options);

			$("#pageloading").hide();
		});

function mixToolbar(querykey, items) {
	items.push({
				id : "delitem",
				icon : "delete",
				text : "删除税务登记信息",
				click : function() {
					var records = ligerGrid.selected;
					if (records.length > 0) {
						var params = {}

						var counter1 = "";

						$.each(records, function(i, n) {
									params["fctrcid_" + i] = n.TRC_ID;
									if (i < records.length - 1) {
										counter1 += i + ",";
									} else {
										counter1 += i;
									}
								});

						params.counter1 = counter1;

						grooveDeleteSubmit("fctrc", "counter1", "multi",
								null, params, function() {
									return true;
								}, function() {
									ligerGrid.reload();
								});
					} else {
						$.ligerDialog.warn("请选择要删除的数据");
					}
				}

			});
}

function defaultFnRender(rowdata, rowindex, value, column) {
	if (column.name == "TRC_REGISTERSTART" || column.name == "TRC_REGISTEREND") {
		return formatDate(value);
	} else if (column.name == "SP") {
		return "<a href=\"javascript:void(0);\" onclick=\"edit('"
				+ rowdata["TRC_ID"] + "')\">编辑</a>";
	}
	return value;
}

var editDialog;

function edit(id) {

	var jsonparams = {
		id : id,
		primaryTable : "fctrc"
	}

	new $.grooveViewPreII(jsonparams, "editfctrc", {
				submitMessage : "确定提交更新",
				OKMessage : "更新成功",
				submitButtonID : "Button1",
				formID : "formID",
				mode : "update",
				beforecall : function() {
					$("#target1").css("display", "none");
				},
				aftercall : function() {
					editDialog.hide();

					ligerGrid.reload();
				},
				rendercall : function(selfFunc, validator, validators, viewConfig) {
					editDialog = $.ligerDialog.open({
								title : "税务登记信息编辑窗口",
								target : $("#target1"),
								height : 300,
								width : 800,
								buttons : [{
									text : '确定',
									onclick : function(item, dialog) {
										$("#formID").handleSubmit(selfFunc,
												validator, validators, viewConfig);
									}
								}, {
									text : '取消',
									onclick : function(item, dialog) {
										dialog.hide();
									}
								}],
								isResize : true
							});
				}
			});
}